(function (doc, win) {
  const docEl = doc.documentElement;
  const resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize';

  const recalc = function () {
      const clientWidth = docEl.clientWidth || 375;
      const maxWidth = 750;

      if (!clientWidth) return;

      const fontSize = Math.min(clientWidth, maxWidth) / (maxWidth / 100);
      docEl.style.fontSize = fontSize + 'px';
  };

  if (!doc.addEventListener) return;
  try {
      win.addEventListener(resizeEvt, recalc, false);
      doc.addEventListener('DOMContentLoaded', recalc, false);
  } catch (error) {
      console.error('Failed to add event listeners:', error);
  }
})(document, window);